type CreateBean<T> = () => T
type UseBean<T> = () => T

export function defineBean<T>(createBean: CreateBean<T>, singleton = true): UseBean<T> {
  if (singleton) {
    let bean: T | null = null
    return function () {
      if (bean == null) {
        bean = createBean()
      }
      return bean
    }
  }
  return function () {
    return createBean()
  }
}
